package it.uiip.crm.utility;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Utility {
	public Utility() {}

	public String date2String(Date data) {
		System.out.println("Data: " + data.toString());
		String stringFormat = "dd/MM/yyyy"; 
		SimpleDateFormat format = new SimpleDateFormat(stringFormat);
		return format.format(data);
	}
	
	public String date2String(Calendar data) {
		System.out.println("Data: " + data.toString());
		Date d = data.getTime();
		String stringFormat = "dd/MM/yyyy";
		SimpleDateFormat format = new SimpleDateFormat(stringFormat);
		return format.format(d);
	}
	
	public Date string2Date(String data) {
		String stringFormat = "dd/MM/yyyy"; 
		DateFormat format = new SimpleDateFormat(stringFormat);
		Date dataD = null;
		try {
			dataD = format.parse(data);
		} catch (ParseException e) {
			System.err.println(e.getMessage());
		}
		return dataD;
	}

}
